<template>
  <el-dialog :visible.sync="show" title="分配角色" @close="closeEvent">
    <h3>{{ val }}</h3>
    <el-checkbox-group v-model="val">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">确定</el-button>
        <el-button @click="show = false">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
import { sysRole } from '@/api/setting'
import { sysUser } from '@/api/user'
import { sysUserAssignRoles } from '@/api/employees'
export default {
  data() {
    return {
      show: false,
      val: [],
      list: [],
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    async getData() {
      const res = await sysRole({
        page: 1,
        pagesize: 9999999
      })
      this.list = res.data.rows
      console.log('角色列表', res)
    },
    // 获取角色回显数据
    async getUserInfo(id) {
      this.id = id
      const res = await sysUser(id)
      this.val = res.data.roleIds || []
      console.log('详情', res)
    },
    // 确定点击
    async submit() {
      await sysUserAssignRoles({
        id: this.id,
        roleIds: this.val
      })
      this.show = false
      this.$message.success('分配角色成功')
    },
    // 关闭回调
    closeEvent() {
      this.val = []
    }
  }
}
</script>
<style></style>
